package mytaxy.tpagp.Drivers;

import mytaxy.tpagp.R;
import mytaxy.tpagp.R.id;
import mytaxy.tpagp.R.layout;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class InfoDriver extends Activity{
	    
		@Override
	    public void onCreate(Bundle savedInstanceState){
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.infodriver);
	        
	        //Obrim la base de dades 'DBDrivers' en mode escriptura
	        DriversSQLiteHelper drdbh = new DriversSQLiteHelper(this, "DBDrivers", null, 1); 
	        final SQLiteDatabase db = drdbh.getWritableDatabase();
	        
	        //Obtenim les dades del driver de la BD
	        Bundle bundle = getIntent().getExtras();	        
	        String[] args = new String[] {bundle.getString("Name")};
	        String[] campos = new String[] {"Nick", "Nationality", "Company", "PhoneNumber", "Trips", "Ranking"};
	        
	        Cursor c = db.query("Drivers", campos, "Name=?",args, null, null, null);
	        
	        //Omplim els camps de text
	        final TextView nameEt = (TextView)findViewById(R.id.Name);
	        nameEt.setText(bundle.getString("Name"));
	        
	        if (c.moveToFirst()) {
	        	String nick = c.getString(0);
	        	final TextView nickEt = (TextView)findViewById(R.id.Nick);
		        nickEt.setText(nick);
		        
		        String nationality = c.getString(1);
		        final TextView nationalityEt = (TextView)findViewById(R.id.Nationality);
		        nationalityEt.setText(nationality);
		        
		        String company = c.getString(2);
		        final TextView companyEt = (TextView)findViewById(R.id.Company);
		        companyEt.setText(company);
		        
		        String phone = c.getString(3);
		        final TextView phoneEt = (TextView)findViewById(R.id.PhoneNumber);
		        phoneEt.setText(phone);
		        
		        String trips = c.getString(4);
		        final TextView tripsEt = (TextView)findViewById(R.id.Trips);
		        tripsEt.setText(trips);
		        
		        String ranking = c.getString(5);
		        final TextView rankingEt = (TextView)findViewById(R.id.Ranking);
		        rankingEt.setText(ranking);
	        }
	        	        
	    
		}
	        
}